<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>attr和prop练习</title>
</head>
<script src="js/jquery-1.12.4.min.js"></script>
<script>
//   $(function(){
//     $('button').click(function(){
//       var url = $('input').val();//获取表单输入的内容
//       console.log('url', url);
//       $('img').prop('src',url);
//     });
// });




// $(function(){
//   $('.btn').click(function(){
//     // var url = $('.inp').val();
//     // console.log('url',url);
//     // $('.img').attr('src',url);
//     var url =' https://img-cdn-qiniu.dcloud.net.cn/uniapp/doc/uniapp4@2x.png';
//     console.log('url',url);
//     var strVar = "";
//     strVar += "<img class=\"img\" src=\""+url+"\">";  //  \" \"  相当于 " "
//     $('.addImg').append(strVar);
//   });
// });

$(function(){
  $('.btn').click(function(){
    var url = 'https://img10.360buyimg.com/img/jfs/t1/159353/17/2928/457625/5ffd107fE2b4a7a10/e0ab266497850f64.gif'
    var strVar = "";
    strVar += "<img src=\""+url+"\" >";
    $('.addImg').append(strVar);
  });
});






 





</script>
<body>
  <!-- <input type="text">
  <button>切换图片</button>
  <p>
    <img src="https://cainiao777.lanzous.com/images/type/apk_max.gif" alt="">
    
  </p> -->



<div class="main">
  <input class="inp" type="text">
  <button class="btn">切换图片</button>
  <p>
    <img class="img" src="https://img-cdn-qiniu.dcloud.net.cn/uniapp/doc/uniapp4@2x.png" alt="">
  </p>
</div>

<div class="addImg"></div>








</body>

<style>
  .main{
    width: 20%;
    margin: 0 auto;
    text-align: center;
    border: 5px #eee solid;
    margin-top: 50px;
    border-radius: 5px;
    padding: 38px;
  }
  .btn{
    background: #1264ab;
    color: #fff;
    border-radius: 5px;
    padding: 10px;
  }
</style>
</html>